/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.PhieuNhapSach;
import Util.DatabaseHandle;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class PhieuNhapSachImpl implements PhieuNhapSachDAO {

    public boolean add(PhieuNhapSach data) {
        String sql = "{call sp_PHIEUNHAPSACH_add(?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setOutParameter(1, java.sql.Types.INTEGER);
            db.setParameter(2, data.getMaNhanVien());
            db.setParameter(3, data.getNgayNhapSach());
            db.setParameter(4, data.getThanhTien());
            db.executeStorePro();
            data.setMaPhieuNhapSach(db.getIntOutValue(1));
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(PhieuNhapSachImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean delete(int MaPhieuNhapSach) {
        String sql = "{call sp_PHIEUNHAPSACH_delete(?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setParameter(1, MaPhieuNhapSach);
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(PhieuNhapSachImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean edit(PhieuNhapSach data) {
        String sql = "{call sp_PHIEUNHAPSACH_edit(?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        try {
            db.setParameter(1, data.getMaNhanVien());
            db.setParameter(2, data.getMaNhanVien());
            db.setParameter(3, data.getNgayNhapSach());
            db.setParameter(4, data.getThanhTien());
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(PhieuNhapSachImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }
    
}
